package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.PcbaProcess;
import com.sailfish.springbootdemo.service.db1.PcbaProcessService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/pcbaProcess")
@CrossOrigin
public class PcbaProcessController {

    @Autowired
    private PcbaProcessService pcbaProcessService;

    @PostMapping("/getAllPcbaProcess")
    public Result getAllPcbaProcess(String searchValue) {
        try {
            return ResultUtil.success(pcbaProcessService.getAllPcbaProcess(searchValue));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/deletePcbaProcessById")
    public Result deletePcbaProcessById(Integer pcbaProcessId) {
        return pcbaProcessService.deletePcbaProcessById(pcbaProcessId);
    }

    @PostMapping("/getPcbaProcessById")
    public Result getPcbaProcessById(Integer pcbaProcessId) {
        try {
            if (pcbaProcessId == null || "".equals(pcbaProcessId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaProcessId", "Miss Param pcbaProcessId", null);
            }
            return ResultUtil.success(pcbaProcessService.getPcbaProcessById(pcbaProcessId));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/addOrUpdatePcbaProcess")
    public Result addOrUpdatePcbaProcess(String mode, PcbaProcess pcbaProcess) {
        return pcbaProcessService.addOrUpdatePcbaProcess(mode, pcbaProcess);
    }
}
